cssprovider: Introduce gtk_css_provider_take_error_full()
authorBenjamin Otte <otte@redhat.com>
Mon, 11 Apr 2011 18:06:39 +0000 (20:06 +0200)
committerBenjamin Otte <otte@redhat.com>
Wed, 18 May 2011 19:58:46 +0000 (21:58 +0200)
Emits the error without the need for a scanner. Also simplifies
gtk_css_provider_take_error() because we now can assert an available
scanner at all times.

gtk/gtkcssprovider.c

index 9616c7ae0503fbd84feaeaec49f60bca364d4ef8..5a5a7f99c82c4d0a4825fe332f6523459555710f 100644 (file)
@@ -846,9 +846,6 @@ static gboolean gtk_css_provider_load_from_path_internal (GtkCssProvider  *css_p
                                                           const gchar     *path,
                                                           gboolean         reset,
                                                           GError         **error);
-static void     gtk_css_provider_take_error (GtkCssProvider *provider,
-                                             GScanner       *scanner,
-                                             GError         *error);
 
 GQuark
 gtk_css_provider_error_quark (void)
@@ -926,6 +923,27 @@ gtk_css_provider_class_init (GtkCssProviderClass *klass)
   g_type_class_add_private (object_class, sizeof (GtkCssProviderPrivate));
 }
 
+static void
+gtk_css_provider_take_error_full (GtkCssProvider *provider,
+                                  GFile          *file,
+                                  guint           line,
+                                  guint           position,
+                                  GError         *error)
+{
+  char *filename;
+
+  if (file)
+    filename = g_file_get_path (file);
+  else
+    filename = NULL;
+
+  g_signal_emit (provider, css_provider_signals[PARSING_ERROR], 0,
+                 filename, line, position, error);
+
+  g_free (filename);
+  g_error_free (error);
+}
+
 static SelectorPath *
 selector_path_new (void)
 {
@@ -1582,7 +1600,11 @@ gtk_css_provider_get_style_property (GtkStyleProvider *provider,
           if (found)
             break;
           
-          gtk_css_provider_take_error (GTK_CSS_PROVIDER (provider), NULL, error);
+          /* error location should be _way_ better */
+          gtk_css_provider_take_error_full (GTK_CSS_PROVIDER (provider),
+                                            NULL,
+                                            0, 0,
+                                            error);
         }
     }
 
@@ -1634,31 +1656,13 @@ gtk_css_provider_take_error (GtkCssProvider *provider,
                              GScanner       *scanner,
                              GError         *error)
 {
-  char *filename;
-  guint line, position;
-
-  if (scanner)
-    {
-      GtkCssScannerPrivate *priv = scanner->user_data;
-      if (priv->file)
-        filename = g_file_get_path (priv->file);
-      else
-        filename = NULL;
-      line = scanner->line;
-      position = scanner->position;
-    }
-  else
-    {
-      filename = NULL;
-      line = 0;
-      position = 0;
-    }
-
-  g_signal_emit (provider, css_provider_signals[PARSING_ERROR], 0,
-                 filename, line, position, error);
+  GtkCssScannerPrivate *priv = scanner->user_data;
 
-  g_free (filename);
-  g_error_free (error);
+  gtk_css_provider_take_error_full (provider,
+                                    priv->file,
+                                    scanner->line,
+                                    scanner->position,
+                                    error);
 }
 
 static void